package com.elite.groovy.callback

import com.elite.groovy.util.EliteBean
import org.apache.commons.logging.Log
import org.apache.commons.logging.LogFactory
import org.springframework.jdbc.core.JdbcTemplate

import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

/**
 *
 * @Title: autoDelYpfPushCustomer*
 * @Description:清理修改时间小于当前时间减去90天push_h5_customer中的数据，清理的数据记录或更新到push_h5_customer_history中；,每天23点执行
 * @remak ：清理修改时间小于当前时间减去90天push_h5_customer中的数据*
 * @author: TH*
 * @date 2023-12-13 11:11:00
 *
 */
class autoDelYpfPushCustomer implements ServiceBackInvoke {
    private static final Log log = LogFactory.getLog(autoDelYpfPushCustomer.class);

    @Override
    public String doCallBack(EliteBean eliteBean, HttpServletRequest request, HttpServletResponse response) {

        JdbcTemplate jt = new JdbcTemplate(eliteBean.getDataSource());

        long starttime = System.currentTimeMillis();
        try {

            String insertsql='''
       insert into
        PUSH_H5_CUSTOMER_HISTORY
        (
        sysid,
        CUSTOMER_GUID,
        CUSLISTNAME,
        CREATEDGROUP,
        CREATEDBY,
        CREATEDDATE,
        ISFLAG,
        REQUESTINFO,
        REQUESTDATE,
        RESPONSEINFO,
        RESPONSEDATE,
        ROLEGROUP_ID,
        REAMRK
        )
                select
        sysguid,
        CUSTOMER_GUID,
        CUSLISTNAME,
        CREATEDGROUP,
        CREATEDBY,
        sysdate,
        ISFLAG,
        REQUESTINFO,
        REQUESTDATE,
        RESPONSEINFO,
        RESPONSEDATE,
        ROLEGROUP_ID,
        '自动清理推送时间小于当前时间减去90天'
        from PUSH_H5_CUSTOMER pu5
    where MODIFIEDDATE<sysdate-90
          '''

            jt.update(insertsql)

           String delsql='''  DELETE FROM push_h5_customer where MODIFIEDDATE<sysdate-90  ''';
           int  delnum  =jt.update(delsql);

            String delsql2='''DELETE FROM Elitethread where Type='YPF' and status='2'  ''';
            int  delnum2  = jt.update(delsql2);
            log.debug("【预评分删除Elitethread多线程表中的数据】本次清理数据数量："+delnum2.toInteger());

            log.debug("【预评分删除当前时间减去90天push_h5_customer中的数据】本次清理数据数量："+delnum.toInteger());
        }  catch (Exception e) {
            log.error("【预评分删除当前时间减去90天push_h5_customer中的数据】清理数据异常：" + e.getMessage());
        }
        long endtime = System.currentTimeMillis();

        log.debug("【预评分删除当前时间减去90天push_h5_customer中的数据】耗时(毫秒)："+(endtime-starttime));


    }


}
